package com.controller;

import com.entity.User;
import com.esDao.EmpDao;
import com.github.pagehelper.PageInfo;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("users")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private EmpDao emp;
    @PostMapping()
    public void addUser(@RequestBody User user){
        userService.addUser(user);
    }
    @DeleteMapping("/{id}")
    public void removeUser(@PathVariable("id") Integer id){
        userService.removeUserById(id);
    }
    @GetMapping("/{id}")
    public User showOne(@PathVariable("id") Integer id){
        return userService.showUserById(id);
    }
    @PutMapping("/{id}")
    public void updateUser(@PathVariable("id") Integer id,@RequestBody User user){
        userService.updateUser(user);
    }
    @GetMapping("/{pageNum}/{pageSize}")
    public PageInfo showAllPage(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize){
        PageInfo<User> userPageInfo = userService.showPageUser(pageNum, pageSize);
        return userPageInfo;
    }
    @GetMapping("/search/{content}")
    public List<User> searchHighLighter(@PathVariable("content") String content){
        List<User> users = emp.searchHighLighter(content);
        return users;
    }
    @GetMapping()
    public List<User> showAll(){
        List<User> users = userService.showUser();
        return users;
    }
}
